<?php if ($id != 0) { ?>
    <script type="text/javascript" src="<?= PATH_URL . 'static/js/admin/uploader/plupload.js' ?>"></script>
    <script type="text/javascript" src="<?= PATH_URL . 'static/js/admin/uploader/plupload.html5.js' ?>"></script>
    <script type="text/javascript" src="<?= PATH_URL . 'static/js/admin/uploader/plupload.html4.js' ?>"></script>
    <script type="text/javascript" src="<?= PATH_URL . 'static/js/admin/uploader/jquery.plupload.queue.js' ?>"></script>
<?php } ?>
<script type="text/javascript">
$(document).ready(function(){
$("#check_hot").hide();
});
function checkField(){
		var type = $("#type").val();
		if(type == 2){
			$("#check_hot").show();
		} else {
			$("#check_hot").hide();
		}
	}

<?php if ($id != 0) { ?>
$(document).ready(function(){
	//===== File uploader =====//
	$("#uploader").pluploadQueue({
		runtimes: 'html5,html4',
		url: root+'admincp/'+module+'/uploader/<?= $id ?>',
		max_file_size: '2mb',
		unique_names: true,
		filters: [
			{title : "Image files", extensions : "jpg,gif,png"}
		]
	});
});

function list_image(){
	$.get(root+"admincp/"+module+"/list_image_of_gallery/<?= $id ?>", function(data) {
		$('#list_image_of_gallery').html(data);
		$('.fancyboxClick').fancybox();
	});
}

function delImage(id){
	if (confirm("Are you sure you want to delete Image?")) {
		$.post(root+"admincp/"+module+"/deleteImageGallery",{
			id: id
		},function(data){
			list_image();
		});
	}
}

list_image();
<?php } ?>

function save(){
	var options = {
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse  // post-submit callback 
    };
	$('#frmManagement').ajaxSubmit(options);
}

function showRequest(formData, jqForm, options) {
	var form = jqForm[0];
	if(form.nameAdmincp.value == ''){
		$('#txt_error').html('Please enter information!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
}

function showResponse(responseText, statusText, xhr, $form) {
	if(responseText=='success'){
		location.href=root+"admincp/"+module+"/#/save";
	}
	
	if(responseText=='error-upload-type'){
		$('#txt_error').html('Only upload Image!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
	
	if(responseText=='error-name-exists'){
		$('#txt_error').html('Category already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}

	/* if(responseText=='permission-denied'){
		show_perm_denied();
	} */
}

</script>
<div class="gr_perm_error" style="display:none;">
    <p><strong>FAILURE: </strong><span id="txt_error">Permission Denied.</span></p>
</div>
<div class="table">
    <div class="head_table">
        <div class="head_title_edit"><?= $module ?></div>
    </div>
    <div class="clearAll"></div>

    <form id="frmManagement" action="<?= PATH_URL . 'admincp/' . $module . '/save/' ?>" method="post"
          enctype="multipart/form-data">
        <input type="hidden" value="<?= $id ?>" name="hiddenIdAdmincp"/>

        <div class="row_text_field_first">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Status:</td>
                    <td class="right_text_field"><input <?php if (isset($result->status)){
                                                        if ($result->status == 1){ ?>checked="checked" <?php }
                                                        }else{ ?>checked="checked"<?php } ?> type="checkbox"
                                                        class="custom_chk" name="statusAdmincp"/></td>
                </tr>
            </table>
        </div>

        <div class="row_text_field">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Name:</td>
                    <td class="right_text_field"><input value="<?php if (isset($result->name)) {
                            print $result->name;
                        } else {
                            print '';
                        } ?>" type="text" name="nameAdmincp"/></td>
                </tr>
            </table>
        </div>

        <div class="row_text_field">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Link:</td>
                    <td class="right_text_field"><input value="<?php if (isset($result->link)) {
                            print $result->link;
                        } else {
                            print '';
                        } ?>" type="text" name="link"/></td>
                </tr>
            </table>
        </div>

        <div class="row_text_field">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Loại gallery:</td>
                    <td class="right_text_field">
                        <select name="type" id="type" style="padding:5px;" onchange="checkField()">
                            <option value="1" <?php if (!empty($result->type)) {
                                ($result->type == '1') ? print 'selected' : '';
                            } ?>>[ Sự kiện đặc biệt ]
                            </option>
                            <option value="2" <?php if (!empty($result->type)) {
                                ($result->type == '2') ? print 'selected' : '';
                            } ?>>[ Vật phẩm đặc biệt ]
                            </option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>

        <div class="row_text_field" id="check_hot">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Hot Gallery:</td>
                    <td class="right_text_field"><input <?php if (isset($result->hot)){
                                                        if ($result->hot == 1){ ?>checked="checked" <?php }
                                                        }else{ ?>checked=""<?php } ?> type="checkbox" class="custom_chk"
                                                        name="hot"/></td>
                </tr>
            </table>
        </div>

        <div class="row_text_field">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                    <td class="left_text_field">Image:</td>
                    <td class="right_text_field"><input type="file"
                                                        name="fileAdmincp[image]"/><?php if (isset($result->image)) {
                            if ($result->image != '') { ?> - <a class="fancyboxClick"
                                                                href="<?= PATH_URL . DIR_UPLOAD_GALLERY_CATEGORY . $result->image ?>">
                                    Review</a><?php }
                        } ?></td>
                </tr>
            </table>
        </div>

    </form>
</div>